new Vue({
    el:'#workOrderApp',
    data:{
        workOrderList:[],  //我的工单对象数组
        workOrder:{},  //我的工单对象
        workOrderPage:{
            curPage:1,  //当前页
            pageCount:1,  //总页数
            rows:10,  //行数
        },
        workOrderMsg:"",  //工单客户回复消息
    },
    mounted:function () {

        this.queryWorkOrder();

    },
    methods:{
        //获取工单信息
        queryWorkOrder:function () {

            var it = this;

            axios({
                url:'/logistics/customer/queryWorkOrder?page='+it.workOrderPage.curPage+"&rows="+it.workOrderPage.rows,
                method:'get'
            }).then(function (res) {

                it.workOrderList = res.data.data.data;

                //算出总页数
                it.workOrderPage.pageCount = parseInt((res.data.data.pageCount+it.workOrderPage.rows-1)/it.workOrderPage.rows);

            }).catch(function (error) {
                console.log("异常啦！！！")
            })

        },
        //查看工单详情信息
        workOrderDetail:function (index) {

            var it = this;

            it.workOrder = it.workOrderList[index];

            $('#workOrderModalId').modal('show');
        },
        //提交工单回复内容
        submitWorkOrderContent:function () {
            var it = this;
            $.ajax({
                url:'/logistics/customer/addWorkOrderContent',
                type:'post',
                data:{
                    customerContent:it.workOrderMsg,
                    workOrderId:it.workOrder.workOrderId
                },
                dataType:'json',
                success:function (res) {
                    if (res.code == 200){
                        var myDate = new Date();
                        var mytime=myDate.toLocaleTimeString();
                        var workOrderContent = {
                            customerContent:it.workOrderMsg,
                            replyContent:'',
                            createTime:mytime
                        };
                        it.workOrder.workOrderContentList.push(workOrderContent);

                        $.toast({
                            title: '信息提示框',
                            subtitle: '10秒后自动关闭',
                            content: '回复成功了哟',
                            type: 'success',
                            delay: 10000,
                            pause_on_hover: false
                        });

                        it.workOrderMsg = "";

                    }else{

                        $.toast({
                            title: '信息提示框',
                            subtitle: '10秒后自动关闭',
                            content: '回复失败，重新试试',
                            type: 'error',
                            delay: 10000,
                            pause_on_hover: false
                        });

                    }
                }
            })

        },
        //修改工单状态
        updateWorkOrderStatus:function (workOrderid,index) {
            var it = this;
            SimpleBsDialog.show({
                width:'20%',
                height:'30%',
                title: '更改工单状态',
                html: '确认是否完成了工单吗?',
                buttons: [{
                        id: 'btn-close',
                        label: 'close',
                        cssClass: 'btn-secondary',
                        action: function(dialogRef) {
                            dialogRef.close();
                        },
                    },
                    {
                        id:'btn-ok',
                        label:'确定',
                        cssClass:'btn-primary',
                        action:function (dialogRef) {
                            $.ajax({
                                url:'/logistics/customer/updateWorkOrder',
                                type:'post',
                                data:{
                                    workOrderId:workOrderid,
                                    workOrderStatus:2
                                },
                                dataType:'json',
                                success:function (res) {
                                    if (res.code == 200){

                                        it.workOrderList[index].workOrderStatus = 2;

                                        $.toast({
                                            title: '信息提示框',
                                            subtitle: '10秒后自动关闭',
                                            content: '您已选择完成工单！',
                                            type: 'success',
                                            delay: 10000,
                                            pause_on_hover: false
                                        });

                                    }else{

                                        $.toast({
                                            title: '信息提示框',
                                            subtitle: '10秒后自动关闭',
                                            content: '提交失败，重新试试',
                                            type: 'error',
                                            delay: 10000,
                                            pause_on_hover: false
                                        });

                                    }
                                }
                            })

                            dialogRef.close();
                        }
                    }

                ],
            });



        },
        //根据时间获取工单信息
        queryWorkOrderByDate:function () {

            var it = this;

            axios({
                url:'/logistics/customer/queryWorkOrder?page='+it.workOrderPage.curPage
                    +"&rows="+it.workOrderPage.rows
                    +"&startDate="+$('#startTime').val()
                    +"&endDate="+$('#endTime').val(),
                method:'get'
            }).then(function (res) {

                it.workOrderList = res.data.data.data;

                //算出总页数
                it.workOrderPage.pageCount = parseInt((res.data.data.pageCount+it.workOrderPage.rows-1)/it.workOrderPage.rows);

            }).catch(function (error) {
                console.log("异常啦！！！")
            })

        },
        //重置搜索日期的文本框
        resetDate:function () {

            $('#startTime').val("");
            $('#endTime').val("")

        }


    }
})
